<?php


class Project_Model extends CI_Model
{
	function __construct()
	{
		parent::__construct();
		$this->load->database();
	}
	
	function delete() 
	{
		
	}
	
	function insert_brief($arr)
	{
		$this->db->insert('sx_project',$arr);
		return $this->db->insert_id();
	}
	
	function update_detail($id, $arr)
	{
		$this->db->where('id',$id);
		$this->db->update('sx_project',$arr);
	}
	
	function select_by_id($id)
	{
		$this->db->where('id',$id);
		$this->db->select('*');
		$query=$this->db->get('sx_project');
		return $query->result();
	}
	
	function select_by_type($type,$sort,$state)
	{
//		$query=$this->db->get_where('sx_project',array('type' => $type, 'sort'=>$sort))
//		 ->order_by($this->_primary, $order);
//		$param = array('type' => 1, 'custom_id' => 1);
//        $this->db->select('*')
//                 ->where($param)                 
//                 ->from($this->_table)
//                 ->order_by($sort, 'desc');
		if($type!=0){
			$this->db->where('type',$type);
		}
		if($state!=0||isset($state)){
			$this->db->where('state',$state);
		}
		//select  concat(currentMoney/collectMoney,'%'   )  as a ,s.*  from sx_project s
		$this->db->select("*,(currentMoney/collectMoney) as per");
		$this->db->order_by($sort);
		$query=$this->db->get('sx_project');
		return $query->result();
	}
}

?>